<%@ page language="java" contentType="text/html; charset=utf-8"%>
<html>
<head>
<%@ include file="/extjs/include/all.jsp"%>
<link
	href="${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl/userModule/page/css/authority.css"
	rel="stylesheet" type="text/css">
<title>添加用户</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/extjs/js/validate.js">
</script>
</head>
<body>
</body>
</html>
<script type="text/javascript">
Ext.onReady(function(){

	Ext.QuickTips.init();  
	<%@ include file="jsp/store.jsp"%>
    //------------------------------------------------------------------------
	//添加用户的表单
	//
	//
	//--------------------------------------------------------------------------
	var addUser = new Ext.FormPanel({
	    labelWidth: 75,
	    url:'${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl::/userModule/action/InsertUser.action',
	    id:'addUser',
	    frame:true,
	    title: '添加用户',
	    bodyStyle:'padding:5px 5px 0',
	    width: 350,
	    defaults: {width: 230},
	    defaultType: 'textfield',
	    items: [{
	            name: 'user_usertype',
	            id: 'usertype',
	            hidden:true,
	            inputType:'hidden',
	            value:'01'
	        },{
	            fieldLabel: '登录名',
	            name: 'user_id',
	            id: 'userid',
	            allowBlank:false,
	            maxLength:10,
	            blankText:'登录名不可为空',
	            vtype: 'isNumberAlphaUnderlineChineseNotStartNumber'
	        },{
	            fieldLabel: '姓名',
	            name: 'user_username',
	            id: 'username',
	            maxLength:10,
	            allowBlank:false,
	            blankText:'姓名不可为空',
	            vtype: 'isNumberAlphaUnderlineChinese'
	        },{
	            fieldLabel: '密码',
	            name: 'user_password',
	            id: 'password',
	            maxLength:16,
	            inputType: 'password',
	            allowBlank:false,
	            blankText:'密码不可为空',
	            vtype: 'isNumberAlphaUnderline'
	        }, {
	            fieldLabel: '确认密码',
	            name: 'password1',
	            id: 'password1',
	            maxLength:16,
	            inputType: 'password',
	            vtype: 'repetition',
	            allowBlank:false,
	            blankText:'确认密码不可为空',
               	repetition: { targetCmpId: 'password'}
	        },　{
	            xtype:'combo',
                fieldLabel: '职位',
                name: 'user_position_show',
                id: 'user_position_show',
                store: qx_position_store,
		        displayField:'value',
		        valueField :'key',  
		        hiddenName: 'user_position' ,
		        typeAhead: true,
		        mode: 'local',
		        forceSelection: true,
		        triggerAction: 'all',
		        emptyText:'请选择职位...',
		        selectOnFocus:true,
		        editable: false,
		        allowBlank:false,
	            blankText:'职位不可为空'
	        },{
	            xtype:'combo',
                fieldLabel: '机构',
                name: 'user_dept_id_show',
                store: dept_store,
		        displayField:'value',
		        valueField :'key',  
		        hiddenName: 'user_dept_id' ,
		        typeAhead: true,
		        mode: 'local',
		        forceSelection: true,
		        triggerAction: 'all',
		        emptyText:'请选择机构...',
		        selectOnFocus:true,
		        editable: false,
		        allowBlank:false,
	            blankText:'机构不可为空'
	        },{
	        	xtype:'textarea',
	            fieldLabel: '描述',
	            name: 'user_descn',
	            id: 'descn',
	            vtype: 'isNumberAlphaUnderlineChineseSpaceMaxLength200'
	        } 
	    ]
	});

	//--------------------------------------------------------------------------------------------
	//						添加用户
	//
	//--------------------------------------------------------------------------------------------
			
	if(!win){
         var win = new Ext.Window({
            layout      : 'fit',
            width       : 450,
            height      : 350,
            plain       : true,
            animEl: 'result',
            closable: false,
            items: [addUser],
            buttons: [{
               text     : '添加',
               handler  : function(){
                   	if(addUser.form.isValid()){
                   		addUser.form.submit({
	                		url: '${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl::/userModule/action/InsertUser.action', 
	                		success : function(form, action) {
	                			var myResult = Ext.util.JSON.decode(action.response.responseText);
	                			if (myResult.success == 'true') {
	                				if(myResult.result > 0){
	                					Ext.MessageBox.show({
	                				 		title: '添加成功',
		                                    msg: '恭喜您，添加用户成功！',
		                                    width:200,
		                                    buttons: Ext.MessageBox.OK,
		                                    fn: function(btn) {
										         window.location = '${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl/userModule/page/userList.jsp';
										    }
		                                 });                                    
									  } else {
											  	Ext.MessageBox.show({
				                                    title: '添加失败',
				                                    msg: '对不起，该用户已经存在！',
				                                    buttons: Ext.MessageBox.OK,
				                                    icon: Ext.MessageBox.ERROR
			                                	});
									  }  
	                            } else {
		                            	Ext.MessageBox.show({
		                                    title: '添加失败',
		                                    msg: '对不起，添加用户失败！',
		                                    buttons: Ext.MessageBox.OK,
		                                    icon: Ext.MessageBox.ERROR
	                                	});
	                            }
	                        },
	                        failure : function(form, action) {
	                        	
	                        	Ext.MessageBox.show({
                                    title: '添加失败',
                                    msg: '对不起，添加用户失败！',
                                    buttons: Ext.MessageBox.OK,
                                    icon: Ext.MessageBox.ERROR
                                });
	                        },
	                		waitMsg:'正在添加用户，请稍后...'
                		});
                   	} else {
                   		Ext.MessageBox.alert('警告','对不起，您的信息有误！')
                   	}
                 }
            },{
                text     : '返回',
                handler  : function(){
                	//window.history.back();
                	window.location = 'userList.jsp'
                    //win.hide();
                    }
           },{
                text     : '重置',
                handler  : function(){
                    addUser.form.reset(); 
                }
            }]
        });
    }
    win.show();
    document.getElementById('userid').maxLength = 10;
	document.getElementById('username').maxLength = 10;
	document.getElementById('password').maxLength = 16;
	document.getElementById('password1').maxLength = 16;
});
</script>